package com.zhl.test;


import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.Subscription;

public class RxDemo {

    public static void main(String[] args) {
        Observable<Integer> observable= Observable.create(new Observable.OnSubscribe<Integer>() {
             @Override
             public void call(Subscriber<? super Integer> subscriber) {
                 for(int i=0;i<5;i++){
                     subscriber.onNext(i);
                 }
                 subscriber.onCompleted();
             }
         });

        //Observable.subscribe(Observer)，Observer订阅了Observable
        Subscription subscribe = observable.subscribe(new Observer<Integer>() {
            @Override
            public void onCompleted() {
                System.out.println("完成");
            }
            @Override
            public void onError(Throwable e) {
                System.out.println("异常");
            }
            @Override
            public void onNext(Integer integer) {
                System.out.println("接收Obsverable中发射的值：" + integer);
            }
        });
    }
}
